package com.gy.blockchain.web.controller;

import com.alibaba.fastjson.JSON;
import com.gy.blockchain.web.service.BlockService;
import com.gy.blockchain.web.util.BlockCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
public class BlockController {

    @Resource
    BlockService blockService;

    @Autowired
    BlockCache blockCache;

    /**
     * 查看当前节点区块链数据
     */
    @GetMapping("/sacn")
    @ResponseBody
    public String scanBlock(){
        return JSON.toJSONString(blockCache.getBlockChain());
    }

    /**
     * 创建创世区块
     */
    @GetMapping
    @ResponseBody
    public String createFirstBlock(){
        blockService.createGenesisBlock();
        return JSON.toJSONString(blockCache.getBlockChain());
    }

}
